package com.shop.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration
@EnableSwagger2//开启Swagger2
public class SwaggerConfig {

    //胚子swagger2Bean实例
    @Bean
    public Docket docket() {
        System.out.println("=========swagger日记开启====================");
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
//                    RequestHandlerSelectors配置要扫描接口的方式
                //basePackage("com.shop.controller"):指定扫描的包  使用最多
                //any 扫描全部
                //none 都不扫描
                // withClassAnnotation(RestController.class) 扫描类上的注解
                .apis(RequestHandlerSelectors.any())
                .build();
//        配置swagger信息=apiinfo
    }

    private ApiInfo apiInfo() {

        //作者信息
        Contact contact = new Contact("sjy", "https://gitee.com/sjyllj/springcloud", "995251681@qq.com");

        return new ApiInfo(
                "sjy的swagger接口日记api文档",
                "作者有点酷",
                "1.0",
                "https://gitee.com/sjyllj/springcloud",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList());
    }
}
